package com.lh.ssm.service.impl;

import com.lh.ssm.domain.User;
import com.lh.ssm.mapper.UserMapper;
import com.lh.ssm.service.UserService;
import com.lh.ssm.util.MailUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    public User checkUsername(String username) {
        User result = userMapper.findUserByName(username);
        return result;
    }

    public int register(User user) {
        int i = userMapper.addUser(user);
        if (i > 0) {
            MailUtils.sendMail(user);
        }
        return i;

    }

    public int active(String code)
    {
        int userId = userMapper.getUserIdByCode(code);

        return userMapper.active(userId);

    }

    @Override
    public User login(String username, String password) {
        User user = userMapper.getUserByName(username,password);
        return user;
    }
}
